package com.baomibing.flow.model;

import com.baomibing.flow.constant.NodeTypeEnum;
import com.baomibing.flow.constant.ParallelExeTypeEnum;
import com.baomibing.flow.constant.ParallelModelEnum;
import com.baomibing.flow.execute.Execution;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * ParallelNode
 *
 * @author frog 2023/9/18 17:41
 * @version 1.0.0
 **/
@Slf4j
@Data @Accessors(chain = true) @EqualsAndHashCode(callSuper = true)
@ToString
public class ParallelNode extends WorkNode {

    private ParallelModelEnum model;
    private ParallelExeTypeEnum exeType;
    @Override
    public void execute(Execution execution) {
        log.info("*****process: 正在执行ParallelNode({}),执行人:{}" ,this.getName(), execution.getActor());
        List<TransitionNode> outputs = getOutputs();
        flow.doParallelProcess(this, execution);
    }

    @Override
    public void reject(Execution execution) {
        log.info("*****reject: 正在执行ParallelNode({}}),执行人:{}" ,this.getName(), execution.getActor());
        for (TransitionNode line : getInputs()) {
            line.reject(execution);
        }
    }

    public ParallelNode(String name) {
        this.name = name;
        this.nodeType = NodeTypeEnum.Parallel.name();
    }

    //for json deserialize
    public ParallelNode() {
        this.nodeType = NodeTypeEnum.Parallel.name();
    }
}
